package cc.icourt.kit.adapter;

import android.text.Layout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cc.icourt.kit.R;
import cc.icourt.kit.domain.MainItem;
import cc.icourt.kit.typerwriter.TypeWriterTextView;

/**
 * -----------------------------------------------
 * 作    者：高延荣
 * 电    话：18963580395
 * 创建日期：2024/6/5 15:59
 * 描    述：des:
 * 修订历史：
 * -----------------------------------------------
 */
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {

    private List<MainItem> items;

    public MainAdapter(List<MainItem> list) {
        this.items = list;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_rv_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tv.setGravity(items.get(position).tag == 0 ? Gravity.START : Gravity.END);
        if (items.get(position).tag == 0) {
            holder.tv.setText(items.get(position).content);
        } else {
            holder.typeTv.setText(items.get(position).content,true);
        }

    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tv;
        TypeWriterTextView typeTv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
            typeTv = itemView.findViewById(R.id.typeTv);
        }


    }
}
